package com.info.zhiduoduo.admin.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.info.zhiduoduo.admin.model.formbean.system.ListOperationLogFormBean;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.common.utils.DateUtil;
import com.info.zhiduoduo.repository.entity.system.SystemOperationLog;
import com.info.zhiduoduo.repository.mapper.system.SystemOperationLogMapper;

import org.springframework.stereotype.Service;

import java.util.Date;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class SystemOperationLogService {

	@Resource
	SystemOperationLogMapper systemOperationLogMapper;

	public SmartResult<SystemOperationLog> list(BaseSimpleFormBean<ListOperationLogFormBean> formBean) {
		ListOperationLogFormBean reqdata = formBean.getReqdata();
		Date from = DateUtil.defaultInitial(reqdata.getFrom());
		Date to = DateUtil.defaultEndless(reqdata.getTo());
		Integer userType = reqdata.getUserType();
		if (userType == null) userType = -1;

		Page<SystemOperationLog> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
		systemOperationLogMapper.list(reqdata.getName(), reqdata.getType(), userType, reqdata.getUsername(), from, to);
		return SmartResult.ofPage(page);
	}

}
